package com.buss.product.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;


@Entity
@Table(name="base_goodsdetail")
@TableGenerator(name="goodsdetail_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
		pkColumnValue="goodsdetail_seq",valueColumnName="seq_val",table="product_pk_sequence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class GoodsDetail implements Serializable{

	private static final long serialVersionUID = 1L;

	/**表主键*/
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE,generator = "goodsdetail_pk_sequence")
	private Long id;
	
	/**商品信息*/
	@ManyToOne(cascade = CascadeType.REFRESH,fetch=FetchType.EAGER)
	@JoinColumn(name="goodsId",nullable=false)
	private Goods goods;
	
	/**商品条形码*/
	@Column(length = 20,nullable=false)
	private String barCode;
	
	/**参考零售价格*/
	@Column(nullable=false,precision=4)
	private Float price;
	
	/**属性内容信息*/
	@Lob
	private String propContext;

	/**属性内容值，是包括引号的，便于转换为json格式*/
	@Lob
	private String propContextValue;
	
	/**属性内容值，该属性内容值是将propContextValue中的引号去掉了的*/
	@Transient
	private String PropContextValueClear;
	
	public GoodsDetail(){}
	
	public GoodsDetail(Long id,String propContext){
		this.id = id;
		this.propContext = propContext;
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public String getBarCode() {
		return barCode;
	}

	public void setBarCode(String barCode) {
		this.barCode = barCode;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public String getPropContext() {
//		if(StringUtil.isNotEmpty(propContext)){
//			return propContext.substring(1, propContext.length() - 2);
//		}
		return propContext;
	}

	public void setPropContext(String propContext) {
		//this.propContext = "," + propContext + ",";
		this.propContext = propContext;
	}

	public String getPropContextValue() {
		return propContextValue;
	}

	public void setPropContextValue(String propContextValue) {
		this.propContextValue = propContextValue;
	}

	public String getPropContextValueClear() {
		if(propContextValue == null){ 
			propContextValue = "";
		}
		return propContextValue.replaceAll("'", "");
	}

	public void setPropContextValueClear(String propContextValueClear) {
		PropContextValueClear = propContextValueClear;
	}
	
}
